<?php

declare(strict_types=1);

namespace App\Chat\Amqp\Producers;

use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage;
use PhpAmqpLib\Message\AMQPMessage;

#[Producer(exchange: 'ws_route', routingKey: 'ws_route')]
class WebSocketProducer extends ProducerMessage
{
    public function __construct(array $data)
    {
        // 设置不同 pool
        $this->poolName = 'default';
        $this->payload = $data;
    }

    public function setPayload($data): self
    {
        $this->payload = $data;
        return $this;
    }

    public function getProperties(): array
    {
        return [
            'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT
        ];
    }
}